/**
 * chenxitech.cn Inc.
 * Copyright (c) 2017-2017 All Rights Reserved.
 */
package tbdp.tool.datasource;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;

import tbdp.tool.util.GsonUtils;
import tbdp.tool.util.ResourceUtil;

/**
 * @author xbkaishui
 * @version $Id: DataSourceLocater.java, v 0.1 2017-06-17 下午3:08 xbkaishui Exp $$
 */
public class DataSourceLocater {

    private static final String basePath = "datasource/";
    private static final String suffix = ".ds";

    /**
     * 加载数据源信息
     */
    public DataSourceConfig locate(String name) {
        String fileName = name + suffix;
        try {
            InputStream ins = ResourceUtil.getInputStream(basePath + fileName);
            String content = IOUtils.toString(ins, "UTF-8");
            return GsonUtils.fromJson(content, DataSourceConfig.class);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
